function changeDefaultCategory(id,URL){
	
	$.ajax({
        type: "POST",
        url: URL + "/" + id,
        dataType: "json",
        //data: "catId="+id,
        cache:false,
        success: 
          function(result){
                window.location.reload(true);
          }
        
        });

      return false;
}

function add_to_cart(id,link){
	
	$.post(link + "/cart/add_cart_item", { product_id: id, quantity: 1, ajax: '1' },
  			function(data){
  			if(data == 'true'){
  				$('#cart-content').load( link + "/cart/show_cart");
  				/*
    			$.get(url + "/cart/show_cart", function(cart){
    				//alert(cart);
  					$("#cart-content").html(cart);
				});
				*/
    		}else{
    			alert("Product does not exist");
    		}	
    		
 		 }); 

	return false;
}



function update_to_cart(id,link,q,p){
	qty = $('#' + q).val();
	
	if(qty < 1){
		remove_to_cart(id, link);
		return false;
	}
	
	$.ajax({
        type: "POST",
        url: link + "/cart/update_cart_item",
        dataType: "json",
        data: "rowid="+id+"&quantity="+qty+"&price="+p,
        cache:false,
        success: 
          function(result){
        		//alert(result.subtotal);
        		if(result.message == 'true'){
        			$('#product-subtotal').html(result.subtotal);
        			$('#cart-total').html(result.total);
        			$('#cart-content').load(link + "/cart/show_cart");
        		}
                //window.location.reload(true);
          }
        
    });
	/*
	$.post(link + "/cart/update_cart_item", { rowid: id, quantity: qty, ajax: '1', price: p },
  			function(data){
				
				alert(data.message);
		
			
  			if(data == 'true'){
  				$('#cart-content').load(link + "/cart/show_cart");
  				$('#content').load(link + "/cart/show_items");
    		}else{
    			alert("Can't update product quantity");
    		}	
    		
 		 });
 	
 	*/
	
	return false;
}

function remove_to_cart(id,link){
	$.post(link + "/cart/remove_cart_item", { rowid: id, quantity: 0, ajax: '1' },
  			function(data){
  			if(data == 'true'){
  				$('#cart-content').load(link + "/cart/show_cart");
  				$('#content').load(link + "/cart/show_items");
    		}else{
    			alert("Can't remove product quantity");
    		}	
    		
 		 });
 	
	
	return false;
}

function login(link) {
	// Get the product ID and the quantity 
	var user = $('#login-form').find('input[name=user]').val();
	var pass = $('#login-form').find('input[name=password]').val();
  

    //return false; // Stop the browser of loading the page defined in the form "action" parameter. 
	
	$.post(link + "/user/login_ajax", { username: user, password: pass, ajax: '1' },
			function(data){
				if(data == 'true'){
					/*
					$.get(link + "/user/show_user", function(user){
						$("#top-menu-right").html(user);
						
					});
					*/	
					
					$('.a1').load(link + "/user/show_hello");
					$('.a2').load(link + "/user/show_logout");
					$('.a3').load(link + "/user/show_profile");
					
					
				}else{
					alert('login failed');
				}	
	 });
	return false;
}

function checkSignedIn(){
	$.post(link + "/user/checkSignedIn",
			function(data){
				if(data == 'true'){
			
				}else{
					
					return false;
				}	
	 });
}
